<html>
<head><title>Nicofarre test</title></head>
<body style="margin: 0; cursor: none">
<script src="../tma.js"></script>
<script src="mv_common.js"></script>
<script>

var snd;
document.body.addEventListener('keydown', function (e) {
  switch (e.which) {
    case 49:  // 1
      snd.fetch('data/bustling.mp3', true);
      break;
    case 50:  // 2
      snd.capture();
      break;
  }
});

tma.extlibs = [ 'ext/gl-matrix.js', 'ext/mv/MajVj.js' ];
tma.onload = function () {
  MajVj.setSetting('misc', 'sound', 'useMicrophone', true);
  MajVj.loadAllPlugins().then(_(function () {
    var r = 1;
    var width = 1920 / r;
    var height = 1080 / r;
    var vj = new MajVj(width, height, true);
    snd = vj.create('misc', 'sound', { delay: 0.0 });
    snd.fetch('data/bustling.mp3', true);
    var fft = new Float32Array(snd.getFftCount());
    controller.sound = {
        fftDb: fft
    };
    var panel = vj.create('frame', 'nicofarre', {
        led: MajVj.frame.nicofarre.LED_FRONT_BOTH,
        mirror: MajVj.frame.nicofarre.MIRROR_ON_LEFT,
        frames: [
            { name: 'specticle', options: { controller: controller } }
            ]});
    var fx = vj.create('effect', 'nicofarre');
    fx.setController(controller);
    var fbo = vj.screen().createFrameBuffer(width, height);
    vj.run(function (delta) {
      snd.getFloatFrequencyData(fft);
      if (emulate)
        fbo.bind();
      vj.screen().setAlphaMode(false);
      vj.screen().fillColor(0.0, 0.0, 0.0, 1.0);
      try { panel.draw(delta); } catch (e) { console.error(e.stask); }
      if (emulate) {
        vj.screen().bind();
        vj.screen().setAlphaMode(false);
        fx.draw(delta, fbo.texture);
      }
      vj.screen().flush();
    });
    window.onresize = function () {
      vj.onresize();
      fx.onresize(vj.aspect());
    };
  }), function (e) { console.error('plugin load error: ' + e.stack); });
};
</script>
</body>
</html>
